﻿#ifndef TOOL_XML_H
#define TOOL_XML_H

#include <QString>
#include <QtXml>
#include <cluster.h>

typedef enum
{
    XML_TYPE_TEXT,
    XML_TYPE_INT,
}Xml_Type_e;

class ToolXml
{
public:
    ToolXml();

    QString makeLoadXml(QString sn);
    int readLoadXml(QString xml, struct ClusterInfo_s info);

    QString makeHeartbeatXml(QString sn);
    int readHeartbeatXml(QString xml);

    QString makeGetClusterXml(QString sn);
    int readGetClusterXml(QString xml, Cluster * c);

    QString makeGetLocalXml(QString sn, int busId, QString maddr);
    int readGetLocalXml(QString xml, LocalDev * ld);

    QString makeSetMotor(QString sn, LocalDev *ld, int m, int mode, int type, double speed, double trip, int power);
    QString makeRebootLocal(QString sn, int busId, QString maddr, ClusterSet_e cmdType);

    QString makeSetLocalXml(LocalDev * ld);
    QString makeSetClusterXml(Cluster * clus);

    QString makeGetCmdXml(LocalDev * ld);
    int readGetCmdXml(QString xml, localCmd_t * cmd);
    QString makeSetCmdXml(LocalDev * ld);

    QString makeGetDnaXml(LocalDev * ld);
    int readGetDnaXml(QString xml, localDna_t * dns);
    QString makeSetDnaXml(LocalDev * ld);

    int readMotorRefrXml(QString xml, LocalDev * ld);

    int readRetXml(QString xml);

private:
    QDomElement addElement(QString key, QString value);

//    void getElement(QDomElement * e, QString tag, void * data, int type);
};

#endif // TOOL_XML_H
